<%= render partial: 'shipit/stacks/header', locals: { stack: @stack } %>

<div class="wrapper">
  <section>
    <header class="section-header">
      <h2>Settings (Stack #<%= @stack.id %>)</h2>
    </header>

    <div class="setting-section">
      <%= form_for @stack do |f| %>
        <div class="field-wrapper">
          <%= f.label :environment %>
          <%= f.text_field :environment, placeholder: 'production' %>
        </div>

        <div class="field-wrapper">
          <%= f.label :deploy_url, 'Deploy URL (Where is this stack deployed to?)' %>
          <%= f.text_field :deploy_url, placeholder: 'https://' %>
        </div>

        <div class="field-wrapper">
          <%= f.check_box :continuous_deployment %>
          <%= f.label :continuous_deployment, 'Enable continuous deployment' %>
        </div>

        <div class="field-wrapper">
          <%= f.check_box :ignore_ci %>
          <%= f.label :ignore_ci, "Don't require CI to deploy" %>
        </div>

        <%= f.submit class: "btn", value: "Save" %>
      <% end %>
    </div>

    <div class="setting-section">
      <h5>Lock deploys</h5>
      <%= form_for @stack do |f| %>
        <div class="field-wrapper">
          <%= f.label :lock_reason, 'Reason for lock' %>
          <%= f.text_area :lock_reason %>
        </div>
        <% if @stack.locked? %>
          <%= f.submit class: "btn", value: "Update Reason" %>
        <% else %>
            <%= f.submit class: "btn", value: "Lock" %>
        <% end %>
      <% end %>
      <% if @stack.locked? %>
        <%= form_for @stack do |f| %>
          <%= f.hidden_field :lock_reason, value: nil %>
          <%= f.submit class: "btn btn--primary", value: "Unlock" %>
        <%- end -%>
      <% end %>
    </div>
    <div class="setting-section">
      <h5>Resynchronize this stack</h5>
      <table>
        <tr>
          <td><%= button_to "Webhooks", stack_sync_webhooks_path(@stack), class: "btn", method: "post" %></td>
          <td>Ensure that all required webhooks have been created.</td>
        </tr>
        <tr>
          <td><%= button_to "Clear Git Cache", stack_clear_git_cache_path(@stack), class: "btn", method: "post" %></td>
          <td>Delete the local git mirror in case it's in a bad state.</td>
        </tr>
      </table>
    </div>


    <div class="setting-section">
      <h5>Delete this stack</h5>
      <p>This action will delete the stack from Ship it permanently. Be careful.</p>
      <%= button_to "Delete…", stack_path(@stack), class: 'btn btn--delete', data: {confirm: 'Are you sure?'}, method: :delete %>
    </div>

  </section>
</div>
